﻿<%@ CodePage = 65001 %>


<!--#include file="includes/database.asp" -->
<!--#include file="includes/global_varaiable.asp" -->
<!--#include file="film_info.asp" -->


<%
Response.expires = 0
Response.expiresabsolute = Now() - 1
Response.addHeader "pragma", "no-cache"
Response.addHeader "cache-control", "private"
Response.addHeader "cache-control", "no-cache"
Response.addHeader "cache-control", "no-store"
Response.CacheControl = "no-cache"

nStartRec = 0
nStopRec = 0
nTotalRecs = 0
nRecCount = 0
nRecActual = 0
sDeleteConfirmMsg = "Bạn có chắc chắn muốn xóa tất cả những dữ liệu đã chọn không?"
nDisplayRecs = 20
nRecRange = 10

Dim t_SessionID

Const StartRec = "start"
Const SessionStartRec = "film_start"
Const ewSessionMessage = "Message"

' Set Up Inline Edit Parameters
sAction = ""

%>
<!--#include file="header.asp"-->

<script type="text/javascript" src="ew.js"></script>

<script type="text/javascript">
<!--
function EW_selectKey(elem) {
	var f = elem.form;	
	if (!f.key_d) return;
	if (f.key_d[0]) {
		for (var i=0; i<f.key_d.length; i++)
			f.key_d[i].checked = elem.checked;	
	} else {
		f.key_d.checked = elem.checked;	
	}
	ew_clickall(elem);
}
function EW_selected(elem) {
	var f = elem.form;	
	if (!f.key_d) return false;
	if (f.key_d[0]) {
		for (var i=0; i<f.key_d.length; i++)
			if (f.key_d[i].checked) return true;
	} else {
		return f.key_d.checked;
	}
	return false;
}
//-->
</script>
<%

sSQL = "SELECT * FROM CHITIETPHIM a INNER JOIN CHANNEL b ON a.ChannelID = b.ChannelID INNER JOIN STUDIO c ON a.StudioID = c.StudioID INNER JOIN THELOAI d ON a.GenreID = d.GenreID"

' Set up Record Set
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 3
rs.Open sSql, adoCon, 1, 2
nTotalRecs = rs.RecordCount
If nDisplayRecs <= 0 Then ' Display All Records
	nDisplayRecs = nTotalRecs
End If
nStartRec = 1
SetUpStartRec() ' Set Up Start Record Position
%>
<p><span class="aspmaker">TABLE: CHITIETPHIM</span></p>

<%
If Session(ewSessionMessage) <> "" Then
%>
<p><span class="ewmsg"><%= Session(ewSessionMessage) %></span></p>
<%
	Session(ewSessionMessage) = "" ' Clear message
End If
%>

<table class="ewListAdd">
	<tr>
		<td><span class="aspmaker"><a href="film_add.asp">Add</a></span></td>
	</tr>
</table>
<p>
<% If nTotalRecs > 0 Then %>
<form name="film_list" id="film_list" action="film_list.asp" method="post">
<table id="ewlistmain" class="ewTable">
	<!-- Table header -->
	<tr class="ewTableHeader">
		<td valign="top"><span>Sticky</span></td>
		<td valign="top"><span>Status</span></td>
		<td valign="top"><span>Film ID</span></td>
		<td valign="top"><span>Channel</span></td>
		<td valign="top"><span>Title</span></td>
		<td valign="top"><span>Genre</span></td>
		<td valign="top"><span>Director</span></td>
		<td valign="top"><span>Actor</span></td>
		<td valign="top"><span>Length</span></td>
		<td valign="top"><span>Studio</span></td>
		<td valign="top"><span>Country</span></td>
		<td valign="top"><span>Date Created</span></td>
		
<td>&nbsp;</td>
<td><input type="checkbox" class="aspmaker" onClick="EW_selectKey(this);"></td>
	</tr>
<%

' Avoid starting record > total records
If CLng(nStartRec) > CLng(nTotalRecs) Then
	nStartRec = nTotalRecs
End If

' Set the last record to display
nStopRec = nStartRec + nDisplayRecs - 1

' Move to first record directly for performance reason
nRecCount = nStartRec - 1
If Not rs.Eof Then
	rs.MoveFirst
	rs.Move nStartRec - 1
End If
nEditRowCnt = 0
nRecActual = 0
Do While (Not rs.Eof) And (nRecCount < nStopRec)
	nRecCount = nRecCount + 1
	If CLng(nRecCount) >= CLng(nStartRec) Then
		nRecActual = nRecActual + 1

	' Set row color
	sItemRowClass = " class=""ewTableRow"""
	
	' Display alternate color for rows
	If nRecCount Mod 2 <> 1 Then
		sItemRowClass = " class=""ewTableAltRow"""
	End If
	x_Status = rs("Status")
	x_Sticky = rs("IsSticky")
	x_FilmID = rs("FilmID")
	x_Channel = rs("ChannelName")
	x_Title = rs("Title")
	x_Genre = rs("Genre")
	x_Director = rs("Director")
	x_Actor = rs("Actor")
	x_Length = rs("Length")
	x_Studio = rs("StudioName")
	x_Country = rs("Country")
	x_DateCreated = rs("DateCreated")
	
	bEditRow = (CStr(Session(ewSessionTblKey & "_FilmID")&"") = CStr(x_FilmID&"")) And (nEditRowCnt = 0)
	If bEditRow Then
		nEditRowCnt = nEditRowCnt + 1
		sItemRowClass = " class=""ewTableEditRow"""
		
	End If
%>
	<!-- Table body -->
	<tr<%=sItemRowClass%><%=sListTrJs%>>
	
	<!-- Sticky -->
		<td align="center"><span>
<% 
	If x_Sticky = true then
	Response.Write("<img src=""images/sticky.png"" border=""0"">")
	else
	Response.Write(" ")
	end if
%>
		</span></td>

	<!-- Status -->
	<td align="center"><span>

<% 
	If x_Status = True then
	Response.Write("<img src=""images/yes_1.png"" border=""0"">")
	else
	Response.Write("<img src=""images/no_1.png"" border=""0"">")
	end if
%>

	</span></td>
	
	<!-- FilmID -->
	<td><span>
<% Response.Write x_FilmID %>

	</span></td>

	<!-- Channel -->
	<td><span>

<% Response.Write x_Channel %>

	</span></td>

	<!-- Title -->
	<td><span>
<% Response.Write x_Title %>

	</span></td>

	<!-- Genre -->
	<td><span>

<% Response.Write x_Genre %>

	</span></td>

	<!-- Director -->
	<td><span>

<% Response.Write x_Director %>

	</span></td>

	<!-- Actor -->
	<td><span>

<% Response.Write x_Actor %>

	</span></td>

	<!-- Length -->
	<td><span>

<% Response.Write x_Length %>

	</span></td>

	<!-- Studio -->
	<td><span>

<% Response.Write x_Studio %>

	</span></td>

	<!-- Country -->
	<td><span>

<% Response.Write x_Country %>

	</span></td>

	<!-- DateCreated -->
	<td><span>

<% Response.Write x_DateCreated %>

	</span></td>

<td><span class="aspmaker">
<a href="<% If Not IsNull(x_FilmID) Then Response.Write "film_edit.asp?FilmID=" & Server.URLEncode(x_FilmID) Else Response.Write "javascript:alert('Invalid Record! Key is null');" End If %>">Edit</a>
<% End If %>
</span></td>
<td><span class="aspmaker"><input type="checkbox" name="key_d" value="<%= x_FilmID %>" class="aspmaker" onclick='ew_clickmultidelete(this);'>Delete</span></td>
	</tr>
<%
	rs.MoveNext
Loop
%>
</table>
<% If nRecActual > 0 Then %>
<p>
<input type="button" name="btndelete" value="DELETE SELECTED" onClick="if (!EW_selected(this)) alert('Bạn chưa chọn dữ liệu để xóa!'); else if (ew_confirm('<%=sDeleteConfirmMsg%>')) {this.form.action='film_delete.asp';this.form.encoding='application/x-www-form-urlencoded';this.form.submit();}">
<p>
<% End If %>
</form>
<% If LCase(sAction) = "edit" Then %>
<% End If %>
<% End If %>
<%

' Close recordset and adoConection
rs.Close
Set rs = Nothing
adoCon.Close
Set adoCon = Nothing
%>
<form action="film_list.asp" name="ewpagerform" id="ewpagerform">
<table border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td nowrap>
<%
If nTotalRecs > 0 Then
	rsEof = (nTotalRecs < (nStartRec + nDisplayRecs))
	PrevStart = nStartRec - nDisplayRecs
	If PrevStart < 1 Then PrevStart = 1
	NextStart = nStartRec + nDisplayRecs
	If NextStart > nTotalRecs Then NextStart = nStartRec
	LastStart = ((nTotalRecs-1)\nDisplayRecs)*nDisplayRecs+1
	%>
	<table border="0" cellspacing="0" cellpadding="0"><tr><td><span class="aspmaker">Page&nbsp;</span></td>
<!--first page button-->
	<% If CLng(nStartRec)=1 Then %>
	<td><img src="images/firstdisab.gif" alt="First" width="16" height="16" border="0"></td>
	<% Else %>
	<td><a href="film_list.asp?start=1"><img src="images/first.gif" alt="First" width="16" height="16" border="0"></a></td>
	<% End If %>
<!--previous page button-->
	<% If CLng(PrevStart) = CLng(nStartRec) Then %>
	<td><img src="images/prevdisab.gif" alt="Previous" width="16" height="16" border="0"></td>
	<% Else %>
	<td><a href="film_list.asp?start=<%=PrevStart%>"><img src="images/prev.gif" alt="Previous" width="16" height="16" border="0"></a></td>
	<% End If %>
<!--current page number-->
	<td><input type="text" name="pageno" value="<%=(nStartRec-1)\nDisplayRecs+1%>" size="4"></td>
<!--next page button-->
	<% If CLng(NextStart) = CLng(nStartRec) Then %>
	<td><img src="images/nextdisab.gif" alt="Next" width="16" height="16" border="0"></td>
	<% Else %>
	<td><a href="film_list.asp?start=<%=NextStart%>"><img src="images/next.gif" alt="Next" width="16" height="16" border="0"></a></td>
	<% End If %>
<!--last page button-->
	<% If CLng(LastStart) = CLng(nStartRec) Then %>
	<td><img src="images/lastdisab.gif" alt="Last" width="16" height="16" border="0"></td>
	<% Else %>
	<td><a href="film_list.asp?start=<%=LastStart%>"><img src="images/last.gif" alt="Last" width="16" height="16" border="0"></a></td>
	<% End If %>
	<td><span class="aspmaker">&nbsp;of <%=(nTotalRecs-1)\nDisplayRecs+1%></span></td>
	</tr></table>
	<% If CLng(nStartRec) > CLng(nTotalRecs) Then nStartRec = nTotalRecs
	nStopRec = nStartRec + nDisplayRecs - 1
	nRecCount = nTotalRecs - 1
	If rsEOF Then nRecCount = nTotalRecs
	If nStopRec > nRecCount Then nStopRec = nRecCount %>
	<span class="aspmaker">Records <%= nStartRec %> to <%= nStopRec %> of <%= nTotalRecs %></span>
<% Else %>
	<% If sSrchWhere = "0=101" Then %>
	<span class="aspmaker"></span>
	<% Else %>
	<span class="aspmaker">No records found</span>
	<% End If %>
<% End If %>
		</td>
	</tr>
</table>
</form>
<!--#include file="footer.asp"-->
<%

'-------------------------------------------------------------------------------
' Function SetUpStartRec
' - Set up Starting Record parameters based on Pager Navigation
' - Variables setup: nStartRec

Sub SetUpStartRec()
	Dim nPageNo

	' Check for a START parameter
	If Request.QueryString(StartRec).Count > 0 Then
		nStartRec = Request.QueryString(StartRec)
		Session(SessionStartRec) = nStartRec
	ElseIf Request.QueryString("pageno").Count > 0 Then
		nPageNo = Request.QueryString("pageno")
		If IsNumeric(nPageNo) Then
			nStartRec = (nPageNo-1)*nDisplayRecs+1
			If nStartRec <= 0 Then
				nStartRec = 1
			ElseIf nStartRec >= ((nTotalRecs-1)\nDisplayRecs)*nDisplayRecs+1 Then
				nStartRec = ((nTotalRecs-1)\nDisplayRecs)*nDisplayRecs+1
			End If
			Session(SessionStartRec) = nStartRec
		Else
			nStartRec = Session(SessionStartRec)
			If Not IsNumeric(nStartRec) Or nStartRec = "" Then
				nStartRec = 1 ' Reset start record counter
				Session(SessionStartRec) = nStartRec
			End If
		End If
	Else
		nStartRec = Session(SessionStartRec)
		If Not IsNumeric(nStartRec) Or nStartRec = "" Then
			nStartRec = 1 'Reset start record counter
			Session(SessionStartRec) = nStartRec
		End If
	End If
End Sub

'-------------------------------------------------------------------------------
' Function ResetCmd
' - Clear list page parameters
' - RESET: reset search parameters
' - RESETALL: reset search & master/detail parameters
' - RESETSORT: reset sort parameters


%>

<%

'-------------------------------------------------------------------------------
' Recordset updating event

Function Recordset_Updating(rsold, rsnew)
	On Error Resume Next

	' Please enter your customized codes here
	Recordset_Updating = True
End Function

'-------------------------------------------------------------------------------
' Recordset updated event

Sub Recordset_Updated(rsold, rsnew)
	On Error Resume Next
End Sub
%>
